package com.jaws.demo.controller;

import com.jaws.core.common.vo.OpRequest;
import com.jaws.core.common.vo.OpResponse;
import com.jaws.demo.domain.AccountTrade;
import com.jaws.demo.service.AccountTradeService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * sharding jbdc demo
 * 操作 account_order{0..7} , account_flow{0..9}
 *
 * @author liangqm
 * @date 2018-05-03 9:56:18
 * @since v1.0.0
 */
@RestController
@RefreshScope
@Slf4j
@ApiModel("sharding jdbc 测试, account_trade{0..7} , account_flow{0..9}")
public class AccountApiController {

	@Resource
	AccountTradeService accountTradeService;

	@PostMapping(value = "/addAccountTrade")
	@ApiOperation(value = "添加一条账户交易记录")
	public OpResponse addAccountTrade(@ApiParam(value = "请求参数", required = true) @RequestBody @Valid OpRequest<AccountTrade> req) throws Exception {
		accountTradeService.trade(req.getParams());
		return OpResponse.success();
	}

	@PostMapping(value = "/batchAddAccountTrade")
	@ApiOperation(value = "批量插入账户交易记录")
	public OpResponse batchAddAccountTrade(@ApiParam(value = "请求参数", required = true) @RequestBody @Valid OpRequest<List<AccountTrade>> req) throws Exception {
		accountTradeService.batchTrade(req.getParams());
		return OpResponse.success();
	}
}
